import detail from './user/detail.json'
import login from './user/login.json'
import deptHorizon from './user/dept-horizon.json'
import Bamboo from "@/lang/bamboo";

/**
 * 是否处于测试模式
 *
 * 有时候，写前端代码，不希望有后台的参与，此时需要一些逻辑，取消后台的代码控制
 *
 * @type {boolean}
 */
let is_debug = true;

class User {
    detail() {
        return new Promise((resolve, reject) => {
            resolve(detail);
        });
    }

    login(username, password) {
        return new Promise((resolve, reject) => {
            resolve(login);
        });
    }


    /**
     * 查询平级部门
     * @return {Promise<[any]>}
     */
    deptHorizon() {
        return new Promise((resolve, reject) => {
            resolve(deptHorizon);
        });
    }

    /**
     * 查询平级部门树
     * @return {Promise<[any]>}
     */
    deptHorizonTree() {
        return new Promise((resolve, reject) => {
            let list = deptHorizon;
            let arr = Bamboo.wrapList(list, Bamboo.getNameOption());
            let tree = Bamboo.toTree(arr);
            resolve(tree);
        });
    }
}

const user = new User();

const BAPI = class {
    /**
     * 设置模式
     * @param val 是否处于测试模式
     */
    static setDebug(val) {
        is_debug = val;
    }

    /**
     * 鉴权相关的配置
     * @return {User}
     */
    static user() {
        return user;
    }
}

export default BAPI;